$(function(){
    var tableSource = new $.jqx.dataAdapter({
        dataType: "json",
        dataFields:[
            { name: "id", type: "int" },
            { name: "uuid", type: "string" },
            { name: "createTime", type: "string" },
            { name: "updateTime", type: "string" },
            { name: "keyword", type: "string"},
            { name: "creator", type: "string"},
            { name: "mender", type: "string"},
            { name: "isShow", type: "int"}
        ],
        id: "id",
        url: "recommend/all.do"
    });
    // 以下是列表中显示的列
    $("#dataTable").jqxDataTable({
        width: "100%",
        source: tableSource,
        pageable: true,
        pageSize: 15,
        serverProcessing: true,
        pagerButtonsCount: 10,
        columnsResize: true,
        sortable: true,
        columns: [
            { text: "序号", width: 50, cellsRenderer: function(row) { return (row + 1).toString(); } },
            { text: "创建时间", dataField: "createTime", cellsRenderer: function(row,column,value,rowData){
            	return value.substring(0,19);
            }},
            { text: "修改时间", dataField: "updateTime", cellsRenderer: function(row,column,value,rowData){
            	return value.substring(0,19);
            }},
            { text: "关键字", dataField: "keyword" },
            { text: "创建者", dataField: "creator" },
            { text: "修改者", dataField: "mender" },
            { text: "操作", dataField: "isShow", cellsRenderer: function(row, column, value, rowData){
            	return ["<input type='button' onclick=\"showOrHidden('"+ rowData.uuid +"', 1)\" class='btn-sm btn-primary' value='设置显示' />", "<input type='button' onclick=\"showOrHidden('"+ rowData.uuid +"', 0)\" class='btn-sm btn-warning' value='取消显示' />"][value];}}
        ],
    });
    $("#dataTable").on();
    $("#dataTable").on("rowDoubleClick",function(info, args){
        if(args && args.flag){
            info = args;
        }
        editingIndex = info.args.index;
        editingData = info.args.row;
        _editerIndex = layer.open({
            id: "roleEditer",
            title: "添加/修改/推荐搜索词",
            type: 1,
            skin: "layui-layer-rim",
            area: ["340px", "200px"],
            content:
            '<div id="role-editer" class="form" style="height: 95%;overflow: auto;">' +
            '<div style="text-align: center;"><span style="font-size:16px;">推荐关键词默认不显示</span></div>' +
            '<input type="hidden" name="id" />' +
            '<input type="hidden" name="submit-url" value="recommend/updateRecommend.do" />' +
            '<label class="from-label update" for="name">搜索关键字：</label>' +
            '<input type="text" name="keyword" allowBlank="false" class="form-control" placeholder="推荐关键字" />' +
            '<div class="form" style="position: absolute;bottom: 0px;width: 100%;text-align: right;background-color: #DDD;">' +
            '<input type="button" class="btn btn-sm btn-success" onclick="submitEditer(this)" value="保存"/>' +
            '<input type="button" class="btn btn-sm btn-info" onclick="closeEditer(this)" value="返回"/>' +
            '</div></div>',
/*            success : function(e) {
                $.ajax({
                    async: false,
                    type:"post",
                    url: "role/treePerm.do",
                    success: function(data, status) {
                        var treeView = $("#perTree");
                        var source=[];
                        for(var i = 0; i < data.data.length; i++){
                            if(data.data[i].puuid==null){
                                var data={ label: data.data[i].name,id:data.data[i].uuid,items:[] };
                                for(var j = 0; j < data.data.length; j++){
                                    if(data.data[j].puuid==data.data[i].uuid){
                                        data.items.push({ label: data.data[j].name,id:data.data[j].uuid });
                                    }
                                }
                                source.push(data);
                            }
                        }
                        treeView.jqxTree({checkboxes:true,source: source, width: "23%", height: 650});
                        treeView.on("select", function(event){
                            //event.args.owner.selectedItem.id
                        });
                    }
                });
            }*/
        });
        setData($("#role-editer"), editingData);
    });
});

function showOrHidden(uuid, state){
	$.ajax({
		type:"post",
		url: "recommend/showOrHiddenRecommend.do",
		data: {"uuid": uuid, "isShow": state},
		success:function(result){
			layer.msg(result.msg);
			update($("#dataTable"));
		}
	});
}